/**
 * 技师经营项目管理初始化
 */
var ArtificerBusiness = {
    id: "ArtificerBusinessTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ArtificerBusiness.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '项目ID', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '业务名称', field: 'businessName', visible: true, align: 'center', valign: 'middle'},
            {title: '项目描述', field: 'describe', visible: true, align: 'center', valign: 'middle'},
            {title: '注意事项', field: 'pointsAttention', visible: true, align: 'center', valign: 'middle'},
            {title: '服务时长(分钟)', field: 'serviceDuration', visible: true, align: 'center', valign: 'middle'},
            {title: '技师id', field: 'artificerId', visible: true, align: 'center', valign: 'middle'},
            {title: '下单须知', field: 'orderNotice', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
            {title: '好评率', field: 'praiseRate', visible: true, align: 'center', valign: 'middle'},
            {title: '总订单数', field: 'totalCount', visible: true, align: 'center', valign: 'middle'},
            {title: '折扣率(%)', field: 'discount', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'},
            {title: '项目价格 元', field: 'price', visible: true, align: 'center', valign: 'middle'},
            {title: '默认项目 1 默认选择 0飞默认', field: 'ced', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
ArtificerBusiness.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ArtificerBusiness.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加技师经营项目
 */
ArtificerBusiness.openAddArtificerBusiness = function () {
    var index = layer.open({
        type: 2,
        title: '添加技师经营项目',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/artificerBusiness/artificerBusiness_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看技师经营项目详情
 */
ArtificerBusiness.openArtificerBusinessDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '技师经营项目详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/artificerBusiness/artificerBusiness_update/' + ArtificerBusiness.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除技师经营项目
 */
ArtificerBusiness.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/artificerBusiness/delete", function (data) {
            Feng.success("删除成功!");
            ArtificerBusiness.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("artificerBusinessId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询技师经营项目列表
 */
ArtificerBusiness.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    ArtificerBusiness.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = ArtificerBusiness.initColumn();
    var table = new BSTable(ArtificerBusiness.id, "/artificerBusiness/list", defaultColunms);
    table.setPaginationType("client");
    ArtificerBusiness.table = table.init();
});
